import http from "../../api/http"
import home from "./home"
export default {
    namespaced: true,    // 开启命名空间
    state: {
        userdata: null,     // 用户信息
        routerlist: []  // 该用户的动态路由信息
    },
    mutations: {
        setrouterlist(state, val) {
            state.routerlist = val
        },
        setuserdata(state, val) {
            state.userdata = val
        }
    },
    getters: {
        gettersUsername(state) {
            return state.userdata.username + "李白修饰可好"
        },
        gettersHomeData(state) {
            return home.state.homedata + "-----user页面调用home页面的数据"
        }
    },
    actions: {
        async asyncGetUserdata(context) {
            let data = await http({
                url: "ceshi",
                method: "get",
            })

            // console.log(data)
            sessionStorage.setItem("routerlist", JSON.stringify(data.data))

            context.commit("setrouterlist", data.data)  //触发mutation中的方法
        }
    }
}